/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlanificacionPanel.java
 *
 * Created on 05-may-2011, 14:11:24
 */

package ia_psr.transportesGUI;

import ia_psr.builder.GrafoEmpresaTransportesBuilder;
import ia_psr.builder.GraphBuilder;
import ia_psr.graph.GrafoEmpresaTransportes;
import ia_psr.graph.Tarea;
import ia_psr.problemas.Variable;
import ia_psr.problemas.transportes.Conductor;
import ia_psr.problemas.transportes.EmpresaTransportes;
import java.awt.Color;
import java.awt.image.ColorModel;
import javax.swing.JLabel;
import javax.swing.table.TableModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Rubén Avalos Elvira y Fabiana Celiberti Tapie
 */
public class PlanificacionPanel extends javax.swing.JPanel {
    private EmpresaTransportes et;
    private GraphBuilder builder;

    /** Creates new form PlanificacionPanel */
    public PlanificacionPanel() {
        initComponents();
    }

    public void populatePlanTable() {
        DefaultTableModel model = new DefaultTableModel();
        et = EmpresaTransportes.getInstance();
        builder = GrafoEmpresaTransportesBuilder.getInstance();
        GrafoEmpresaTransportes g = (GrafoEmpresaTransportes)builder.getBuildedGraph();
        int ncolumnas = et.elementos.size();

        // TABLA SEGUN HORARIO DE TRABAJO
        // intervalos de una hora entre filas
        int nfilas    = (et.horarioEmpresa.horaFin - et.horarioEmpresa.horaInicio);
        // intervalos de media hora entre filas
        //int nfilas     = ((et.horarioEmpresa.horaFin - et.horarioEmpresa.horaInicio) * 2;
        int horaActual = et.horarioEmpresa.horaInicio;
        model.setRowCount(nfilas);

        int rowIndex;
        Object[] columnData;

        columnData = new Object[nfilas];
        for (int i = 0; i < nfilas; ++i, ++horaActual) {
            columnData[i] = String.valueOf(horaActual) + " - " + String.valueOf(horaActual+1);
        }

        model.addColumn("Hora", columnData);

        for (Variable v : et.elementos) {
            Conductor c = (Conductor)v;

            columnData = new Object[nfilas];

            for (Tarea t : c.tareasAsignadas) {
                for ( rowIndex = t.h.horaInicio - et.horarioEmpresa.horaInicio;
                      rowIndex < t.h.horaFin - et.horarioEmpresa.horaInicio;
                      ++rowIndex ) {
                    columnData[rowIndex] = t.nombre;
                }
            }

            model.addColumn(c.getValue(), columnData);

        }

        planTable.setModel(model);

    }

    public void clearData() {
        planTable.setModel(new DefaultTableModel());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        planTable = new javax.swing.JTable();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Plan de trabajo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(102, 102, 102))); // NOI18N

        planTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(planTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable planTable;
    // End of variables declaration//GEN-END:variables

}
